package com.hitsz.cdq;

import android.app.Fragment;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import static com.hitsz.cdq.MainActivity.IP_ADDRESS_SERVER;
import static com.hitsz.cdq.MainActivity.PORT_SERVER;


/**
 * Created by ChenDongqiang on 2017/3/1.
 */
public class SettingFragment extends Fragment {
    private Button btn_save,btn_edit;
    private EditText tv_port, ip_address;
    private TextView tv_state;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.content_setting, container, false);
        tv_port = (EditText) view.findViewById(R.id.tv_port);
        tv_port.setText(PORT_SERVER);
        tv_port.setEnabled(false);
        ip_address = (EditText) view.findViewById(R.id.ip_address);
        ip_address.setText(IP_ADDRESS_SERVER);
        ip_address.setEnabled(false);
        tv_state = (TextView) view.findViewById(R.id.tv_state);
        btn_save = (Button) view.findViewById(R.id.btn_save);
        btn_save.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PORT_SERVER=tv_port.getText().toString();
                IP_ADDRESS_SERVER=ip_address.getText().toString();
                tv_state.setText("保存成功");
                tv_state.setTextColor(Color.GREEN);
                btn_save.setEnabled(false);
                btn_edit.setEnabled(true);
                tv_port.setEnabled(false);
                ip_address.setEnabled(false);
            }
        });

        btn_edit= (Button) view.findViewById(R.id.btn_edit);
        btn_edit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                tv_state.setText("编辑中");
                tv_state.setTextColor(Color.RED);
                btn_save.setEnabled(true);
                btn_edit.setEnabled(false);
                tv_port.setEnabled(true);
                ip_address.setEnabled(true);
            }
        });
        btn_save.setEnabled(false);
        btn_edit.setEnabled(true);
        return view;
    }


}
